##
# libxmp Makefile fragment
##


.PHONY: ${libxmp}_clean


libxmp_base = contrib/libxmp

libxmp_include = -I${libxmp_base}/include


libxmp_cflags = \
 -I${libxmp_base}/src \
 -I${libxmp_base}/src/loaders \
 ${libxmp_include} -w -O3 \
 -include src/platform_endian.h


SRC_OBJS	= virtual.o format.o period.o player.o read_event.o dataio.o \
		  fnmatch.o md5.o lfo.o scan.o control.o \
		  med_extras.o filter.o effects.o mixer.o mix_all.o \
		  load_helpers.o load.o hio.o hmn_extras.o extras.o smix.o \
		  memio.o mix_paula.o

SRC_PATH	= $(libxmp_base)/src
SRC_OBJ = $(SRC_PATH)/.build


libxmp_objs += $(addprefix $(SRC_OBJ)/,$(SRC_OBJS))


LOADERS	= xm_load.o mod_load.o s3m_load.o stm_load.o 669_load.o far_load.o \
	  mtm_load.o okt_load.o ult_load.o it_load.o amf_load.o asylum_load.o \
	  mmd_common.o mmd1_load.o mmd3_load.o med2_load.o med3_load.o med4_load.o \
	  gdm_load.o st_load.o flt_load.o hmn_load.o

LOADERS_OBJS	= common.o iff.o itsex.o asif.o voltable.o sample.o $(LOADERS)

LOADERS_PATH	= $(libxmp_base)/src/loaders
LOADERS_OBJ	= $(LOADERS_PATH)/.build


libxmp_objs += $(addprefix $(LOADERS_OBJ)/,$(LOADERS_OBJS))


${SRC_OBJ}/%.o: ${SRC_PATH}/%.c
	$(if ${V},,@echo "  CC      " $<)
	${CC} -MD ${CFLAGS} ${libxmp_cflags} -c $< -o $@

${LOADERS_OBJ}/%.o: ${LOADERS_PATH}/%.c
	$(if ${V},,@echo "  CC      " $<)
	${CC} -MD ${CFLAGS} ${libxmp_cflags} -c $< -o $@


-include $(libxmp_objs:.o=.d)


$(libxmp_objs): $(filter-out $(wildcard ${SRC_OBJ}), ${SRC_OBJ})
$(libxmp_objs): $(filter-out $(wildcard ${LOADERS_OBJ}), ${LOADERS_OBJ})

libxmp_clean:
	$(if ${V},,@echo "  RM      " ${SRC_OBJ})
	${RM} -r ${SRC_OBJ}
	$(if ${V},,@echo "  RM      " ${LOADERS_OBJ})
	${RM} -r ${LOADERS_OBJ}
